package com.crayon.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;


public class UTILObj {


	public static Rect getAncherArea(View parent){
		int[] location 		= new int[2];
		parent.getLocationOnScreen(location);

		return new Rect(location[0], location[1], location[0] + parent.getWidth(), location[1] + parent.getHeight());
	}


	public static byte[] composeObjToByteArray(Object obj){
		byte[] byteData=null;
		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(bos);
			oos.writeObject(obj);
			oos.flush();
			oos.close();
			bos.close();
			byteData = bos.toByteArray();
		} catch (Exception e) {
			// TODO: handle exception
			Log.i("", "ERR UTILObj.class " + e.getMessage());
		}
		return byteData;
	}
	public static Object convertByteArrayToObject(byte[] bytearray){
		Object obj = null;
		try {
			ByteArrayInputStream bais = new ByteArrayInputStream(bytearray);
			obj = new ObjectInputStream(bais).readObject();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return obj;
	}
}


